package com.xiaochong.tir.api.controller;

import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.api.service.BtUserService;
import com.xiaochong.tir.api.service.ExchangeInfoService;
import com.xiaochong.tir.api.service.ImmortalsService;
import com.xiaochong.tir.api.util.ApiVersion;
import com.xiaochong.tir.common.data.mapper.ExchangeInfoMapper;
import com.xiaochong.tir.common.data.vo.ApiResultVo;
import com.xiaochong.tir.common.data.vo.CurrencyQuotationResultVo;
import com.xiaochong.tir.common.data.vo.CurrencyQuotationVo;
import com.xiaochong.tir.common.util.ApiResultCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 通证指数
 * @author MengXiangDong
 */
@RestController
@Api(value = "货币行情")
@RequestMapping(value =ApiVersion.API_V1_PREFIX+"/exchange")
public class ImmortalsController {

	@Autowired
	private BtUserService btUserService;

	@Autowired
	private ImmortalsService immortalsService;

	/**
	 * 货币行情
	 */
	@ApiOperation(value = "货币行情" , notes = "货币行情(分页参数：pageIndex,pageSize)")
	@PostMapping("currencyQuotation")
	public ApiResultVo<List<CurrencyQuotationResultVo>> currencyQuotation(@RequestBody CurrencyQuotationVo CurrencyQuotationVo){
		//刷新用户缓存
		if(StringUtils.isNotBlank( CurrencyQuotationVo.getUserToken() )){
			btUserService.setUserCache( CurrencyQuotationVo.getUserToken() );
		}
		ApiResultVo apiResultVo=immortalsService.getCurrencyQuotation(CurrencyQuotationVo);
		return apiResultVo;
	}

	/**
	 * 币种详情(根据cmcId获取)
	 */
	@ApiOperation(value = "币种详情（根据cmcId获取）" , notes = "币种详情（根据cmcId获取）")
	@PostMapping("currencyDetails")
	public ApiResultVo<List<CurrencyQuotationResultVo>> currencyDetails(@RequestParam(value = "cmcId", required = false) String cmcId,
																		@RequestParam(value = "userToken",required = false) String userToken){
		CurrencyQuotationResultVo currencyQuotationResultVo=immortalsService.getCurrencyByCmcId( cmcId,userToken);
		ApiResultVo resultVo=new ApiResultVo();
		if(currencyQuotationResultVo != null){
			resultVo.setData( currencyQuotationResultVo);
			resultVo.setCode( ApiResultCodeUtils.BASE_SUCCESS.getCode());
			resultVo.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
		}else{
			resultVo.setCode( ApiResultCodeUtils.SYSTEM_NULL.getCode());
			resultVo.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
		}
		resultVo.setTradeId(LogTrace.getTrace().getTraceId());
		return resultVo;
	}
}
